import { BodySetup } from "utils/creep/CreepSetup";
import { priority } from "utils/constants/definetypes";
import { role_crossLevel } from "utils/constants/moveConstant";
import { ActionBase, ActionBaseOfCreep } from "../ActionBase";
import { EActionCode } from "framework/FSM/Action/ActionCode";
import { approach } from "GameLoop/WorldState/mount/move/action.virtual";

/**
 * 升级Action
 */
export class ActionBuild  extends ActionBaseOfCreep<IActionCMD<"build">>
{
    protected updateArgs(action: IActionCMD<"build">): EActionCode 
    {
        if(super.updateArgs(action) !== EActionCode.OK)
        {
            return EActionCode.FAILED;
        }
        action.arg.roomObject = Game.getObjectById(action.arg.roomObject?.id) as ConstructionSite;
        if(!action.arg.roomObject)
        {
            return EActionCode.FAILED;
        }
        if(action.arg.entity.store.getUsedCapacity(RESOURCE_ENERGY) == 0)
        {
            return EActionCode.FAILED;
        }
        return EActionCode.OK;
    }
    protected _execute(action: IActionCMD<"build">): EActionCode 
    {
        const site = action.arg.roomObject;
        if(site.pos.distance(action.arg.entity.pos)>3)
        {
            action.arg.entity.memory.crossLevel =role_crossLevel[action.arg.entity.memory.Role];
            action.arg.entity.mymoveTo({pos:site.pos,range:3},{});
        }
        else
        {
            // action.arg.entity.memory.crossLevel = priority.A;
            approach(action.arg.entity,site.pos,3);
            action.arg.entity.build(site);
        }
        return EActionCode.RUNNING;
    }
}